package net.cyndeline.itemEventFactory.actions.defaultImpl

import net.cyndeline.entitySystem.EntityRef
import net.cyndeline.itemEventFactory.Action
import com.escalatesoft.subcut.inject.BindingModule
import com.escalatesoft.subcut.inject.Injectable
import net.cyndeline.events.actions.StealEvent
import net.cyndeline.itemEventFactory.ActionResultConfig
import net.cyndeline.itemEventFactory.ActionResultStorage
import net.cyndeline.itemEventFactory.ActionInput

/**
 * 
 */
trait StealAction extends Action {
}

class Steal(implicit val bindingModule: BindingModule) extends StealAction with Injectable {
  
  override def events(indata: ActionInput) = {
    val result = injectOptional[ActionResultConfig] getOrElse new ActionResultStorage()
    val stealEvent: StealEvent = injectOptional[StealEvent] getOrElse { new net.cyndeline.events.actions.Steal() }
    val user = indata.user
    stealEvent.thief = user
    
    for (target <- indata.targets) {
      if (target.id != user.id) {
        result.addEvent(target, stealEvent)
      }
    }

    result
  }
  
}